package cn.edu.wzu.openlearning.mapper;


import cn.edu.wzu.openlearning.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {


    /**
     * 插入用户
     * @param user
     */
    @Insert("INSERT INTO `user` (`username`, `password`) VALUES (#{username}, #{password})")
    public Integer registerUser(User user);

    /**
     * 查询用户 by username
     * @param username
     * @return User
     */
    @Select("SELECT * FROM user where username=#{username}")
    public User selectUserByUsername(String username);

    /**
     * 查询用户byId
     * @param userId
     * @return User
     */
    @Select("SELECT * FROM user where userId=#{userId}")
    public User selectUserByUserId(Integer userId);

    /**
     * 修改用户密码
     * @param user
     * @return 影响的行数
     */
    @Update("UPDATE `user` SET `password` = #{password} WHERE (`userId` = #{userId})")
    public Integer alterPassword(User user);

    /**
     * 修改用户登录时间
     * @param user
     * @return 影响的行数
     */
    @Update("UPDATE `user` SET `lastLoginTime` = #{lastLoginTime} WHERE (`userId` = #{userId})")
    public Integer alterLastLoginTime(User user);


}
